<?php

namespace App\Http\Middleware;

use Closure;
use EasyWeChat\Foundation\Application;

class AuthWechat
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $open_id = $request->session()->get('wechat_user');
        if (!$open_id) {

            $app = app('wechat');

            $oauth = $app->oauth;
            return $oauth->redirect();
        }
        return $next($request);
    }
}
